/*
 * MainMIDlet.java
 * Main class. Implements the application and control methods.
 *
 * Copyright 2009 by Miguel Moreto.
 * You may use or distribute this code under the terms of the GPL.
 *
 * $Rev: 54 $
 * $LastChangedDate: 2009-07-15 14:22:06 +0000 (Wed, 15 Jul 2009) $
 */

package Main;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;
/**
 * @author moreto
 */
public class MainMIDlet extends MIDlet implements CommandListener, ItemCommandListener {

    private boolean midletPaused = false;

    // Defining variables:
    private IntervalTimer updater;
    private Timer timer;
    private boolean timerRunning;
    private String versionStr = "$Rev: 54 $";

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Form formAbout;
    private ImageItem imageItemAbout;
    private StringItem stringItemAbout;
    private StringItem stringItemVersion;
    private Form formHelp;
    private StringItem stringItem;
    private Form FormSettings;
    private TextField textFieldTzone;
    private ChoiceGroup choiceGroupInversion;
    private ChoiceGroup choiceGroupOrientation;
    private TextField textFieldUserTimeInc;
    private DateField dateFieldAtual;
    private TextField textFieldTimer;
    private List list;
    private ResultCanvas resultCanvas;
    private Command backCommandAbout;
    private Command helpCommand;
    private Command exitCommand;
    private Command StartCommand;
    private Command backCommand1;
    private Command exitCommand1;
    private Command backCommand;
    private Command exitCanvasCommand;
    private Command cancelCanvasCommand;
    private Command itemCommand1;
    private Command itemCommand;
    private Font fontHelp;
    private Image image;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The MainMIDlet constructor.
     */
    public MainMIDlet() {
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getList());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == FormSettings) {//GEN-BEGIN:|7-commandAction|1|18-preAction
            if (command == StartCommand) {//GEN-END:|7-commandAction|1|18-preAction
                // write pre-action user code here
                StartCanvas();//GEN-LINE:|7-commandAction|2|18-postAction
                // write post-action user code here
            } else if (command == backCommand) {//GEN-LINE:|7-commandAction|3|51-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|4|51-postAction
                // write post-action user code here
            } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|5|16-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|6|16-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|7|144-preAction
        } else if (displayable == formAbout) {
            if (command == backCommandAbout) {//GEN-END:|7-commandAction|7|144-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|8|144-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|9|134-preAction
        } else if (displayable == formHelp) {
            if (command == backCommand) {//GEN-END:|7-commandAction|9|134-preAction
                // write pre-action user code here
                switchDisplayable(null, getResultCanvas());//GEN-LINE:|7-commandAction|10|134-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|11|35-preAction
        } else if (displayable == list) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|11|35-preAction
                // write pre-action user code here
                listAction();//GEN-LINE:|7-commandAction|12|35-postAction
                // write post-action user code here
            } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|13|118-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|14|118-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|15|92-preAction
        } else if (displayable == resultCanvas) {
            if (command == cancelCanvasCommand) {//GEN-END:|7-commandAction|15|92-preAction
                // write pre-action user code here
                OnCanvasCancel();//GEN-LINE:|7-commandAction|16|92-postAction
                // write post-action user code here
            } else if (command == exitCanvasCommand) {//GEN-LINE:|7-commandAction|17|87-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|18|87-postAction
                // write post-action user code here
            } else if (command == helpCommand) {//GEN-LINE:|7-commandAction|19|131-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormHelp());//GEN-LINE:|7-commandAction|20|131-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|21|7-postCommandAction
        }//GEN-END:|7-commandAction|21|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|22|
    //</editor-fold>//GEN-END:|7-commandAction|22|


    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: FormSettings ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of FormSettings component.
     * @return the initialized component instance
     */
    public Form getFormSettings() {
        if (FormSettings == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            FormSettings = new Form("Settings", new Item[] { getDateFieldAtual(), getTextFieldTzone(), getChoiceGroupOrientation(), getChoiceGroupInversion(), getTextFieldTimer(), getTextFieldUserTimeInc() });//GEN-BEGIN:|14-getter|1|14-postInit
            FormSettings.addCommand(getExitCommand());
            FormSettings.addCommand(getStartCommand());
            FormSettings.addCommand(getBackCommand());
            FormSettings.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return FormSettings;
    }
    //</editor-fold>//GEN-END:|14-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|15-getter|0|15-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|15-getter|0|15-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|15-getter|1|15-postInit
            // write post-init user code here
        }//GEN-BEGIN:|15-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|15-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: StartCommand ">//GEN-BEGIN:|17-getter|0|17-preInit
    /**
     * Returns an initiliazed instance of StartCommand component.
     * @return the initialized component instance
     */
    public Command getStartCommand() {
        if (StartCommand == null) {//GEN-END:|17-getter|0|17-preInit
            // write pre-init user code here
            StartCommand = new Command("Start", Command.OK, 0);//GEN-LINE:|17-getter|1|17-postInit
            // write post-init user code here
        }//GEN-BEGIN:|17-getter|2|
        return StartCommand;
    }
    //</editor-fold>//GEN-END:|17-getter|2|





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: list ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of list component.
     * @return the initialized component instance
     */
    public List getList() {
        if (list == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            list = new List("Mobile Jupiter 2.0b1 by Moreto", Choice.IMPLICIT);//GEN-BEGIN:|34-getter|1|34-postInit
            list.append("Start", null);
            list.append("Settings", null);
            list.append("About", null);
            list.addCommand(getExitCommand());
            list.setCommandListener(this);
            list.setSelectedFlags(new boolean[] { true, false, false });//GEN-END:|34-getter|1|34-postInit
            // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return list;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: listAction ">//GEN-BEGIN:|34-action|0|34-preAction
    /**
     * Performs an action assigned to the selected list element in the list component.
     */
    public void listAction() {//GEN-END:|34-action|0|34-preAction
        // enter pre-action user code here
        String __selectedString = getList().getString(getList().getSelectedIndex());//GEN-BEGIN:|34-action|1|37-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Start")) {//GEN-END:|34-action|1|37-preAction
                // write pre-action user code here
                StartCanvas();//GEN-LINE:|34-action|2|37-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Settings")) {//GEN-LINE:|34-action|3|39-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormSettings());//GEN-LINE:|34-action|4|39-postAction
                // write post-action user code here
            } else if (__selectedString.equals("About")) {//GEN-LINE:|34-action|5|53-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormAbout());//GEN-LINE:|34-action|6|53-postAction
                // write post-action user code here
            }//GEN-BEGIN:|34-action|7|34-postAction
        }//GEN-END:|34-action|7|34-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|34-action|8|
    //</editor-fold>//GEN-END:|34-action|8|





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">//GEN-BEGIN:|45-getter|0|45-preInit
    /**
     * Returns an initiliazed instance of exitCommand1 component.
     * @return the initialized component instance
     */
    public Command getExitCommand1() {
        if (exitCommand1 == null) {//GEN-END:|45-getter|0|45-preInit
            // write pre-init user code here
            exitCommand1 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|45-getter|1|45-postInit
            // write post-init user code here
        }//GEN-BEGIN:|45-getter|2|
        return exitCommand1;
    }
    //</editor-fold>//GEN-END:|45-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|50-getter|0|50-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|50-getter|0|50-preInit
            // write pre-init user code here
            backCommand = new Command("Back", Command.BACK, 0);//GEN-LINE:|50-getter|1|50-postInit
            // write post-init user code here
        }//GEN-BEGIN:|50-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|50-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: dateFieldAtual ">//GEN-BEGIN:|56-getter|0|56-preInit
    /**
     * Returns an initiliazed instance of dateFieldAtual component.
     * @return the initialized component instance
     */
    public DateField getDateFieldAtual() {
        if (dateFieldAtual == null) {//GEN-END:|56-getter|0|56-preInit
            // write pre-init user code here
            dateFieldAtual = new DateField("Actual time/date:", DateField.DATE_TIME, java.util.TimeZone.getDefault());//GEN-BEGIN:|56-getter|1|56-postInit
            dateFieldAtual.addCommand(getItemCommand1());
            dateFieldAtual.setItemCommandListener(this);
            dateFieldAtual.setDate(new java.util.Date(System.currentTimeMillis()));//GEN-END:|56-getter|1|56-postInit
            // write post-init user code here
        }//GEN-BEGIN:|56-getter|2|
        return dateFieldAtual;
    }
    //</editor-fold>//GEN-END:|56-getter|2|





    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: resultCanvas ">//GEN-BEGIN:|84-getter|0|84-preInit
    /**
     * Returns an initiliazed instance of resultCanvas component.
     * @return the initialized component instance
     */
    public ResultCanvas getResultCanvas() {
        if (resultCanvas == null) {//GEN-END:|84-getter|0|84-preInit
            // write pre-init user code here
            resultCanvas = new ResultCanvas();//GEN-BEGIN:|84-getter|1|84-postInit
            resultCanvas.setTitle("resultCanvas");
            resultCanvas.addCommand(getExitCanvasCommand());
            resultCanvas.addCommand(getCancelCanvasCommand());
            resultCanvas.addCommand(getHelpCommand());
            resultCanvas.setCommandListener(this);
            resultCanvas.setFullScreenMode(true);//GEN-END:|84-getter|1|84-postInit
            // write post-init user code here
        }//GEN-BEGIN:|84-getter|2|
        return resultCanvas;
    }
    //</editor-fold>//GEN-END:|84-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCanvasCommand ">//GEN-BEGIN:|86-getter|0|86-preInit
    /**
     * Returns an initiliazed instance of exitCanvasCommand component.
     * @return the initialized component instance
     */
    public Command getExitCanvasCommand() {
        if (exitCanvasCommand == null) {//GEN-END:|86-getter|0|86-preInit
            // write pre-init user code here
            exitCanvasCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|86-getter|1|86-postInit
            // write post-init user code here
        }//GEN-BEGIN:|86-getter|2|
        return exitCanvasCommand;
    }
    //</editor-fold>//GEN-END:|86-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cancelCanvasCommand ">//GEN-BEGIN:|91-getter|0|91-preInit
    /**
     * Returns an initiliazed instance of cancelCanvasCommand component.
     * @return the initialized component instance
     */
    public Command getCancelCanvasCommand() {
        if (cancelCanvasCommand == null) {//GEN-END:|91-getter|0|91-preInit
            // write pre-init user code here
            cancelCanvasCommand = new Command("Cancel", Command.CANCEL, 0);//GEN-LINE:|91-getter|1|91-postInit
            // write post-init user code here
        }//GEN-BEGIN:|91-getter|2|
        return cancelCanvasCommand;
    }
    //</editor-fold>//GEN-END:|91-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Method: StartCanvas ">//GEN-BEGIN:|109-entry|0|110-preAction
    /**
     * Performs an action assigned to the StartCanvas entry-point.
     */
    public void StartCanvas() {//GEN-END:|109-entry|0|110-preAction
        // write pre-action user code here
        switchDisplayable(null, getResultCanvas());//GEN-LINE:|109-entry|1|110-postAction
        // write post-action user code here

        // Getting the refresh time value from de form:
        String timerStr = getTextFieldTimer().getString(); // Reading the timer from the form.
        java.util.Date date = getDateFieldAtual().getDate(); // Getting the date.

        long ActualTime = date.getTime(); // Actual time in milliseconds setted in the form.
        int tzoneOffset = Integer.parseInt(getTextFieldTzone().getString());
        long timerValue = Integer.parseInt(timerStr); // Refresh time in milliseconds.
        ResultCanvas canvas = getResultCanvas(); // getting the canvas instance.
        canvas.setDate(ActualTime, tzoneOffset);


        // Read diag choice.
        ChoiceGroup choice = getChoiceGroupInversion();
        boolean selected[] = new boolean[choice.size()];
        choice.getSelectedFlags(selected);

        // Setting inversion flags on canvas class:
        canvas.setInvertAllFlag(selected[0]);
        canvas.setInvertHorizontalFlag(selected[1]);
        canvas.setInvertVerticalFlag(selected[2]);

        // Reading screen rotation angle:
        ChoiceGroup choiceDrawAngle = getChoiceGroupOrientation();
        canvas.setAngle(choiceDrawAngle.getSelectedIndex());

        // Reading user time increment:
        String usrTimeIncStr = getTextFieldUserTimeInc().getString();
        canvas.setUserTimeInc(Integer.parseInt(usrTimeIncStr));

        if (timerRunning == false) {
            // Create thread with the date and time setted in the interface:
            updater = new IntervalTimer(timerValue*1000);
            updater.setCanvas(getResultCanvas());
            timer = new Timer();
            timer.schedule(updater, timerValue*1000, timerValue*1000);
            timerRunning = true;
        }
    }//GEN-BEGIN:|109-entry|2|
    //</editor-fold>//GEN-END:|109-entry|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: OnCanvasCancel ">//GEN-BEGIN:|114-entry|0|115-preAction
    /**
     * Performs an action assigned to the OnCanvasCancel entry-point.
     */
    public void OnCanvasCancel() {//GEN-END:|114-entry|0|115-preAction
        // write pre-action user code here
        if (timerRunning){
            timer.cancel();
            timerRunning = false;
            updater.cancel();
        }
        switchDisplayable(null, getList());//GEN-LINE:|114-entry|1|115-postAction
        // write post-action user code here
    }//GEN-BEGIN:|114-entry|2|
    //</editor-fold>//GEN-END:|114-entry|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textFieldTimer ">//GEN-BEGIN:|120-getter|0|120-preInit
    /**
     * Returns an initiliazed instance of textFieldTimer component.
     * @return the initialized component instance
     */
    public TextField getTextFieldTimer() {
        if (textFieldTimer == null) {//GEN-END:|120-getter|0|120-preInit
            // write pre-init user code here
            textFieldTimer = new TextField("Refresh Time [sec]:", "60", 32, TextField.NUMERIC);//GEN-BEGIN:|120-getter|1|120-postInit
            textFieldTimer.setItemCommandListener(this);//GEN-END:|120-getter|1|120-postInit
            // write post-init user code here
        }//GEN-BEGIN:|120-getter|2|
        return textFieldTimer;
    }
    //</editor-fold>//GEN-END:|120-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Items ">//GEN-BEGIN:|8-itemCommandAction|0|8-preItemCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular item.
     * @param command the Command that was invoked
     * @param displayable the Item where the command was invoked
     */
    public void commandAction(Command command, Item item) {//GEN-END:|8-itemCommandAction|0|8-preItemCommandAction
        // write pre-action user code here
        if (item == dateFieldAtual) {//GEN-BEGIN:|8-itemCommandAction|1|128-preAction
            if (command == itemCommand1) {//GEN-END:|8-itemCommandAction|1|128-preAction
                // write pre-action user code here
                getDateFieldAtual().setDate(new java.util.Date(System.currentTimeMillis()));//GEN-LINE:|8-itemCommandAction|2|128-postAction
                // write post-action user code here
            }//GEN-BEGIN:|8-itemCommandAction|3|8-postItemCommandAction
        }//GEN-END:|8-itemCommandAction|3|8-postItemCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|8-itemCommandAction|4|
    //</editor-fold>//GEN-END:|8-itemCommandAction|4|


    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand ">//GEN-BEGIN:|123-getter|0|123-preInit
    /**
     * Returns an initiliazed instance of itemCommand component.
     * @return the initialized component instance
     */
    public Command getItemCommand() {
        if (itemCommand == null) {//GEN-END:|123-getter|0|123-preInit
            // write pre-init user code here
            itemCommand = new Command("Set to actual time", Command.ITEM, 0);//GEN-LINE:|123-getter|1|123-postInit
            // write post-init user code here
        }//GEN-BEGIN:|123-getter|2|
        return itemCommand;
    }
    //</editor-fold>//GEN-END:|123-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand1 ">//GEN-BEGIN:|127-getter|0|127-preInit
    /**
     * Returns an initiliazed instance of itemCommand1 component.
     * @return the initialized component instance
     */
    public Command getItemCommand1() {
        if (itemCommand1 == null) {//GEN-END:|127-getter|0|127-preInit
            // write pre-init user code here
            itemCommand1 = new Command("Reset", Command.ITEM, 0);//GEN-LINE:|127-getter|1|127-postInit
            // write post-init user code here
        }//GEN-BEGIN:|127-getter|2|
        return itemCommand1;
    }
    //</editor-fold>//GEN-END:|127-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: helpCommand ">//GEN-BEGIN:|130-getter|0|130-preInit
    /**
     * Returns an initiliazed instance of helpCommand component.
     * @return the initialized component instance
     */
    public Command getHelpCommand() {
        if (helpCommand == null) {//GEN-END:|130-getter|0|130-preInit
            // write pre-init user code here
            helpCommand = new Command("Help", Command.HELP, 0);//GEN-LINE:|130-getter|1|130-postInit
            // write post-init user code here
        }//GEN-BEGIN:|130-getter|2|
        return helpCommand;
    }
    //</editor-fold>//GEN-END:|130-getter|2|


    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formHelp ">//GEN-BEGIN:|132-getter|0|132-preInit
    /**
     * Returns an initiliazed instance of formHelp component.
     * @return the initialized component instance
     */
    public Form getFormHelp() {
        if (formHelp == null) {//GEN-END:|132-getter|0|132-preInit
            // write pre-init user code here
            formHelp = new Form("Help topics", new Item[] { getStringItem() });//GEN-BEGIN:|132-getter|1|132-postInit
            formHelp.addCommand(getBackCommand());
            formHelp.setCommandListener(this);//GEN-END:|132-getter|1|132-postInit
            // write post-init user code here
        }//GEN-BEGIN:|132-getter|2|
        return formHelp;
    }
    //</editor-fold>//GEN-END:|132-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|135-getter|0|135-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|135-getter|0|135-preInit
            // write pre-init user code here
            stringItem = new StringItem("Mobile Jupiter help", "Key functions:\n*: Change view.\n#: Change keyboard mode.\n\nWhile in Time Mode:\n1: Zoom out;\n2: Fit to screen;\n3: Zoom in;\n4: Decrement 30 minutes;\n5: Plot using the system\'s current time;\n6: Increment 30 minutes;\n7: Decrement by user defined time;\n8: Increment by user defined time;\n0: View orbital paths.\n\nWhile in View Mode:\n1: Rotate screen conterclockwise;\n2: Move drawing up;\n3: Rotate screen clockwise;\n4: Move left;\n5: Center the drawing;\n6: Move to right;\n8: Move down;", Item.PLAIN);//GEN-BEGIN:|135-getter|1|135-postInit
            stringItem.setFont(getFontHelp());//GEN-END:|135-getter|1|135-postInit
            // write post-init user code here
        }//GEN-BEGIN:|135-getter|2|
        return stringItem;
    }
    //</editor-fold>//GEN-END:|135-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: fontHelp ">//GEN-BEGIN:|136-getter|0|136-preInit
    /**
     * Returns an initiliazed instance of fontHelp component.
     * @return the initialized component instance
     */
    public Font getFontHelp() {
        if (fontHelp == null) {//GEN-END:|136-getter|0|136-preInit
            // write pre-init user code here
            fontHelp = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);//GEN-LINE:|136-getter|1|136-postInit
            // write post-init user code here
        }//GEN-BEGIN:|136-getter|2|
        return fontHelp;
    }
    //</editor-fold>//GEN-END:|136-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formAbout ">//GEN-BEGIN:|138-getter|0|138-preInit
    /**
     * Returns an initiliazed instance of formAbout component.
     * @return the initialized component instance
     */
    public Form getFormAbout() {
        if (formAbout == null) {//GEN-END:|138-getter|0|138-preInit
            // write pre-init user code here
            formAbout = new Form("About Mobile Jupiter 2.0b1", new Item[] { getImageItemAbout(), getStringItemAbout(), getStringItemVersion() });//GEN-BEGIN:|138-getter|1|138-postInit
            formAbout.addCommand(getBackCommandAbout());
            formAbout.setCommandListener(this);//GEN-END:|138-getter|1|138-postInit
            // write post-init user code here
        }//GEN-BEGIN:|138-getter|2|
        return formAbout;
    }
    //</editor-fold>//GEN-END:|138-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItemAbout ">//GEN-BEGIN:|139-getter|0|139-preInit
    /**
     * Returns an initiliazed instance of imageItemAbout component.
     * @return the initialized component instance
     */
    public ImageItem getImageItemAbout() {
        if (imageItemAbout == null) {//GEN-END:|139-getter|0|139-preInit
            // write pre-init user code here
            imageItemAbout = new ImageItem("", getImage(), ImageItem.LAYOUT_CENTER, "", Item.PLAIN);//GEN-LINE:|139-getter|1|139-postInit
            // write post-init user code here
        }//GEN-BEGIN:|139-getter|2|
        return imageItemAbout;
    }
    //</editor-fold>//GEN-END:|139-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItemAbout ">//GEN-BEGIN:|140-getter|0|140-preInit
    /**
     * Returns an initiliazed instance of stringItemAbout component.
     * @return the initialized component instance
     */
    public StringItem getStringItemAbout() {
        if (stringItemAbout == null) {//GEN-END:|140-getter|0|140-preInit
            // write pre-init user code here
            stringItemAbout = new StringItem("", "Mobile Jupiter is a J2ME MIDlet application that shows the current position of the galilean moons of Jupiter.\nIt is initially designed to support binocular and telescope observations. Se http://code.google.com/p/mobilejupiter/ for more details.\n\nAcknowledgment:\nGiuliano Gasparini for his insights and valuable help concerning the usability and practical aspecs of MobileJupiter;\nAkkana Peck, for her Jupiter java applet which is the base of this program;\nDan Bruton who also made available a Qbasic routine.\n\nDeveloped by Miguel Moreto\nFlorianopolis, Brazil, 2009");//GEN-BEGIN:|140-getter|1|140-postInit
            stringItemAbout.setItemCommandListener(this);
            stringItemAbout.setFont(getFontHelp());//GEN-END:|140-getter|1|140-postInit
            // write post-init user code here
        }//GEN-BEGIN:|140-getter|2|
        return stringItemAbout;
    }
    //</editor-fold>//GEN-END:|140-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommandAbout ">//GEN-BEGIN:|143-getter|0|143-preInit
    /**
     * Returns an initiliazed instance of backCommandAbout component.
     * @return the initialized component instance
     */
    public Command getBackCommandAbout() {
        if (backCommandAbout == null) {//GEN-END:|143-getter|0|143-preInit
            // write pre-init user code here
            backCommandAbout = new Command("Back", Command.BACK, 0);//GEN-LINE:|143-getter|1|143-postInit
            // write post-init user code here
        }//GEN-BEGIN:|143-getter|2|
        return backCommandAbout;
    }
    //</editor-fold>//GEN-END:|143-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|146-getter|0|146-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|146-getter|0|146-preInit
            // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 0);//GEN-LINE:|146-getter|1|146-postInit
            // write post-init user code here
        }//GEN-BEGIN:|146-getter|2|
        return backCommand1;
    }
    //</editor-fold>//GEN-END:|146-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItemVersion ">//GEN-BEGIN:|147-getter|0|147-preInit
    /**
     * Returns an initiliazed instance of stringItemVersion component.
     * @return the initialized component instance
     */
    public StringItem getStringItemVersion() {
        if (stringItemVersion == null) {//GEN-END:|147-getter|0|147-preInit
            // write pre-init user code here
            stringItemVersion = new StringItem("SVN revision number:", versionStr.substring(5,8));//GEN-BEGIN:|147-getter|1|147-postInit
            stringItemVersion.setFont(getFontHelp());//GEN-END:|147-getter|1|147-postInit
            // write post-init user code here
        }//GEN-BEGIN:|147-getter|2|
        return stringItemVersion;
    }
    //</editor-fold>//GEN-END:|147-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroupInversion ">//GEN-BEGIN:|148-getter|0|148-preInit
    /**
     * Returns an initiliazed instance of choiceGroupInversion component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroupInversion() {
        if (choiceGroupInversion == null) {//GEN-END:|148-getter|0|148-preInit
            // write pre-init user code here
            choiceGroupInversion = new ChoiceGroup("Visual settings:", Choice.MULTIPLE);//GEN-BEGIN:|148-getter|1|148-postInit
            choiceGroupInversion.append("Invert horiz. and vert.", null);
            choiceGroupInversion.append("Invert horizontal", null);
            choiceGroupInversion.append("Invert vertical", null);
            choiceGroupInversion.setSelectedFlags(new boolean[] { false, false, false });
            choiceGroupInversion.setFont(0, null);
            choiceGroupInversion.setFont(1, null);
            choiceGroupInversion.setFont(2, null);//GEN-END:|148-getter|1|148-postInit
            // write post-init user code here
        }//GEN-BEGIN:|148-getter|2|
        return choiceGroupInversion;
    }
    //</editor-fold>//GEN-END:|148-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|151-getter|0|151-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|151-getter|0|151-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|151-getter|1|151-@java.io.IOException
                image = Image.createImage("/logo100x100.png");
            } catch (java.io.IOException e) {//GEN-END:|151-getter|1|151-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|151-getter|2|151-postInit
            // write post-init user code here
        }//GEN-BEGIN:|151-getter|3|
        return image;
    }
    //</editor-fold>//GEN-END:|151-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textFieldTzone ">//GEN-BEGIN:|152-getter|0|152-preInit
    /**
     * Returns an initiliazed instance of textFieldTzone component.
     * @return the initialized component instance
     */
    public TextField getTextFieldTzone() {
        if (textFieldTzone == null) {//GEN-END:|152-getter|0|152-preInit
            // write pre-init user code here
            textFieldTzone = new TextField("Time zone (offset from GMT):", String.valueOf(java.util.TimeZone.getDefault().getRawOffset()/3600000), 32, TextField.NUMERIC);//GEN-LINE:|152-getter|1|152-postInit
            // write post-init user code here
        }//GEN-BEGIN:|152-getter|2|
        return textFieldTzone;
    }
    //</editor-fold>//GEN-END:|152-getter|2|


    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroupOrientation ">//GEN-BEGIN:|162-getter|0|162-preInit
    /**
     * Returns an initiliazed instance of choiceGroupOrientation component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroupOrientation() {
        if (choiceGroupOrientation == null) {//GEN-END:|162-getter|0|162-preInit
            // write pre-init user code here
            choiceGroupOrientation = new ChoiceGroup("Drawing orientation:", Choice.EXCLUSIVE);//GEN-BEGIN:|162-getter|1|162-postInit
            choiceGroupOrientation.append("Draw on horizontal", null);
            choiceGroupOrientation.append("Draw on vertical", null);
            choiceGroupOrientation.append("Draw on diagonal", null);
            choiceGroupOrientation.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);
            choiceGroupOrientation.setSelectedFlags(new boolean[] { true, false, false });
            choiceGroupOrientation.setFont(0, null);
            choiceGroupOrientation.setFont(1, null);
            choiceGroupOrientation.setFont(2, null);//GEN-END:|162-getter|1|162-postInit
            // write post-init user code here
        }//GEN-BEGIN:|162-getter|2|
        return choiceGroupOrientation;
    }
    //</editor-fold>//GEN-END:|162-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: textFieldUserTimeInc ">//GEN-BEGIN:|166-getter|0|166-preInit
    /**
     * Returns an initiliazed instance of textFieldUserTimeInc component.
     * @return the initialized component instance
     */
    public TextField getTextFieldUserTimeInc() {
        if (textFieldUserTimeInc == null) {//GEN-END:|166-getter|0|166-preInit
            // write pre-init user code here
            textFieldUserTimeInc = new TextField("User time increment [min]:", "10", 32, TextField.NUMERIC);//GEN-LINE:|166-getter|1|166-postInit
            // write post-init user code here
        }//GEN-BEGIN:|166-getter|2|
        return textFieldUserTimeInc;
    }
    //</editor-fold>//GEN-END:|166-getter|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay () {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        if (timerRunning){
            timer.cancel();
            updater.cancel();
        }
        
        switchDisplayable (null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet ();
        } else {
            initialize ();
            startMIDlet ();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }

}
